package com.nightsoul.hbase.test.filter;

import java.io.IOException;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.filter.FilterBase;
import org.apache.hadoop.hbase.util.Bytes;

public class PasswordStrengthFilter extends FilterBase {
	private int len;
	private boolean filterRow = false;
	
	public PasswordStrengthFilter() {
	}
	
	public PasswordStrengthFilter(int len) {
		this.len = len;
	}
	
	@Override
	public ReturnCode filterKeyValue(Cell ignored) throws IOException {
		if(Bytes.toString(ignored.getQualifierArray()).equals("pass")) {
			if(ignored.getValueLength()>=len) {
				this.filterRow = true;
				return ReturnCode.SKIP;
			}
		}
		return ReturnCode.INCLUDE;
	}
	
	@Override
	public boolean filterRow() throws IOException {
		return this.filterRow;
	}
	
	
	@Override
	public void reset() throws IOException {
		this.filterRow = false;
	}
	
}
